package com.ml.dao.impl;


import com.ml.dao.BaseDaoBak;
import com.ml.dao.TJUserDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**查看打卡的dao*/
public class TJUserDaoImpl extends BaseDaoBak implements TJUserDao {

    @Override
    /**获取所有用户*/
    public List getAllUser() {
        String sql = "select name from userinfo";
        List<String> list = new ArrayList<String>();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = this.openConnect();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                list.add(rs.getString("name"));
            }
            this.closeConnect(conn, null, ps, rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    /**判断用户是否存在*/
    public  boolean isExistsUser(String user){
        boolean isExists = false;
        String sql="SELECT * FROM USERINFO where name = '"+user+"'";
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            conn=this.openConnect();
            ps=conn.prepareStatement(sql);
            rs=ps.executeQuery();
            while(rs.next()){
                isExists = true;
                break;
            }
            this.closeConnect(conn, null, ps, rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return isExists;
    }

}
